// pages/about/about.js
const app = getApp()
var wh = require("../../utils/wh.js");
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    latitude: '',
    longitude: '',
    setting: {},
    markers: [{
      latitude: '',
      longitude: '', 
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_app_setting();
  },
  //获取小程序设置
  get_app_setting: function () {
    let that = this;
    wh.Post('/api/mall.index/about', {}, function (res) {
      console.log(res)
      let markers = that.data.markers,
      article = res.content;
      WxParse.wxParse('compnay_desc', 'html', article, that);
      markers.latitude = res.lat;
      markers.longitude = res.lng;
      markers.commpany_name = res.company;
      that.setData({
        setting: res,
        latitude: res.lat,
        longitude: res.lng,
        markers: markers
      });
      console.log(markers)
    })
 

  },
  // 打电话
  call: function () {
    let that = this;
    let setting = that.data.setting;
    let tell = setting.tell;

    if (tell == '' || tell == undefined) {

      wx.showModal({
        title: '提示',
        content: '联系电话未设置，不能联系',
        showCancel: false
      })
      return;
    }
    wx.makePhoneCall({
      phoneNumber: tell,
    })
  },



  go: function () {
    var that = this;
    let setting = that.data.setting;
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度  
      success: function (res) {
        var latitude = res.latitude
        var longitude = res.longitude
        var latitudeIdx = Number(setting.lat);
        var longitudeIdx = Number(setting.lng);
        var map_name = setting.company;
        wx.openLocation({
          latitude: latitudeIdx,
          longitude: longitudeIdx,
          name: map_name,
          scale: 15
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})